# coding=utf-8
__author__ = 'liubin'
from tornado.web import asynchronous
from tornado.ioloop import IOLoop
from tornado.gen import coroutine
from tornado.concurrent import run_on_executor
from functools import partial, wraps
from .common import EXECUTOR


def unblock(f):
    @coroutine
    @wraps(f)
    def wrapper(self, *args, **kwargs):
        @run_on_executor
        def callback(self, *args, **kwargs):
            return partial(f, self, *args, **kwargs)()
        result = yield callback(self, *args, **kwargs)
        return result
    return wrapper
